// 第四

// 基于准备好的dom，初始化echarts实例

$.ajax({
    type: "post",
    async: true, //异步执行
    url: "sy/nydsj/trphz",
    dataType: "json", //返回数据形式为json
    success: function (json) {
        var jsonarray= $.parseJSON(json);
        var myChart = echarts.init(document.getElementById('main4'));

// 指定图表的配置项和数据

        option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            color: ['#36e4bb', '#ea97dd', '#7493e5', '#a99cf4', '#fd87ab', '#34abec', '#ebc54a', '#fff45c', '#b3d465', '#cadd9c',],
            series: []
        };
// 使用刚指定的配置项和数据显示图表。

        $.each(jsonarray, function (i, itme) {
            var arrayname = {};
            var normal = {};
            var label = {};
            var itemStyle = {};
            var radius = ['30%', '50%'];
            var a = 20;
            var b = 30;
            var center = [a + i * b + '%', '40%'];

            var color = ['#36e4bb', '#eeeeee'];
            label.show = false;
            normal.label = label;
            itemStyle.normal = normal;

            arrayname.name = itme.massifName;
            arrayname.type = 'pie';
            arrayname.radius = radius;
            arrayname.center = center;
            arrayname.color = color;
            arrayname.data = [];
            arrayname.itemStyle = itemStyle;
            option.series.push(arrayname);
        });
        $.each(jsonarray, function (index, item) {
            var dataa = {};
            var datab = {};
            for (var i = 0; i < option.series.length; i++) {
                if (item.massifName == option.series[i].name) {
                    dataa.value = item.ph;
                    dataa.name = "酸值";
                    datab.value = 14 - dataa.value.valueOf();
                    datab.name = "碱值";
                    option.series[i].data.push(dataa, datab);
                }

            }

        });

        myChart.setOption(option);

    },
    error: function (errorMsg) {
        alert("请求数据失败");
    }
});
